package com.xian.cloud.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @Author: xlr
 * @Date: Created in 下午11:31 2018/11/8
 */
@Configuration
@Import(MailProperties.class)
public class MailConfig {

    @Autowired
    MailProperties mailProperties;
    @Value( "${porxyHost}" )
    private String porxyHost;
    @Value( "${porxyPort}" )
    private String porxyPort;
    @Value( "${proxySet}" )
    private String proxySet;

    @Bean
    public JavaMailSender javaMailSender() {

        Properties properties = new Properties();
        properties.setProperty( "mail.smtp.socks.host", porxyHost );
        properties.setProperty( "mail.smtp.socks.port", porxyPort );
        properties.setProperty( "mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory" );
        properties.setProperty( "mail.smtp.auth", "true" );
        properties.setProperty( "mail.smtp.timeout", "25000" );
        properties.setProperty( "mail.smtp.ssl.enable", "true" );
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setJavaMailProperties( properties );
        mailSender.setHost( mailProperties.getHost() );
        mailSender.setPassword( mailProperties.getPassword() );
        mailSender.setUsername( mailProperties.getUsername() );
        mailSender.setProtocol( mailProperties.getProtocol() );
        return mailSender;
    }



}
